package com.jiyi.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jiyi.activity.new_maintenance.EquipDetailActivity;
import com.jiyi.bean.owner.FloorBean;
import com.swift.maintenance.R;

import java.util.List;

/**
 * 维保派发 adapter
 * 
 * */
public class ChildEquipAdapter extends BaseAdapter {

	private List<FloorBean> dataList;
	private Context mContext;

	public ChildEquipAdapter(Context context, List<FloorBean> data) {
		this.mContext = context;
		this.dataList = data;
	}

	@Override
	public int getCount() {
		if (dataList != null) {
			return dataList.size();
		} else {
			return 0;
		}
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {

			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_equip_more_list, parent, false);

			viewHolder.tvLayout = (TextView) convertView.findViewById(R.id.tvLayout);
			viewHolder.tvNo = (TextView) convertView.findViewById(R.id.tvNo);
			viewHolder.tvDetail = (TextView) convertView.findViewById(R.id.tvDetail);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		final FloorBean equipment = dataList.get(position);
		
		viewHolder.tvLayout.setText(equipment.getFloor_no());
		viewHolder.tvNo.setText(equipment.getEquip_num());
		viewHolder.tvDetail.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Log.e("id       ", equipment.getId());
				Intent intent = new Intent(v.getContext(),EquipDetailActivity.class);
				intent.putExtra("floorId", equipment.getId());
				intent.putExtra("func", 0);
				intent.putExtra("title", "大楼");
				v.getContext().startActivity(intent);
			}
		});
		
				
		return convertView;
	}

	class ViewHolder {

		private TextView tvLayout;
		private TextView tvNo;
		private TextView tvDetail;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

}
